from crouse import models
from rest_framework import serializers

class Category(serializers.ModelSerializer):

    class Meta:
        model = models.CategoryModel
        fields = ["cname","id"]
class CategorySerializer(serializers.ModelSerializer):
    childern = Category(many=True)

    class Meta:
        model = models.CategoryModel
        fields = "__all__"

class CrouseSerializer(serializers.ModelSerializer):
    tea = serializers.SerializerMethodField(read_only=True)
    def get_tea(self, obj):
        return {"tname":obj.teacher.tname,"job":obj.teacher.job,"intro":obj.teacher.intro,"headimg":"http://127.0.0.1:8000"+str(obj.teacher.headimg)}

    class Meta:
        model = models.CrouseDeskModel
        fields = "__all__"

from drf_haystack.serializers import HaystackSerializer
from .search_indexes import CourseIndex
class CourseIndexSerializer(HaystackSerializer):
    class Meta:
        index_classes = [CourseIndex]
        fields = ['text', 'id', 'kname', 'intro','cimg','price','disc']


